package crm.view.Employee;

import com.sun.xml.internal.ws.wsdl.writer.document.Part;
import crm.Utils.RoundBorder;
import crm.dao.impl.EmployeeSqlSeverImpl;
import crm.entity.Employee;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 * 查看职员业绩
 */
public class EmployeePerformance implements ActionListener{
    JFrame frame = null;
    JLabel part = null;
    JLabel performance = null;

    JLabel employeeName = null;

    JTextField partField = null;
    JTextField performanceField = null;
    JTextField employeeNameField = null;

    JButton btn1 = null;
    JButton btn2 = null;



    public static void main(String[] args) {
        new EmployeePerformance();
    }

    public EmployeePerformance() {
        init();
        frame.setBounds(650, 350, 600, 500);
        frame.setLayout(null);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setVisible(true);
    }

    public void init(){
        employeeName = new JLabel("输入职员姓名:");
        employeeNameField = new JTextField();
        frame = new JFrame("业绩情况");
        part = new JLabel("部门:");
        performance = new JLabel("业绩:");
        partField = new JTextField();
        performanceField = new JTextField();
        btn1 = new JButton("查询");
        btn2 = new JButton("清空");
        Font font = new Font("宋体", 2, 25);
        employeeName.setFont(font);
        employeeNameField.setFont(font);
        performance.setFont(font);
        performanceField.setFont(font);
        part.setFont(font);
        partField.setFont(font);
        btn1.setFont(font);
        btn2.setFont(font);

        ImageIcon icon1 = new ImageIcon("src/img/查询2.png");
        btn1.setIcon(icon1);
        btn1.setOpaque(false);
        btn1.setBorder(new RoundBorder());
        btn1.setBorder(new RoundBorder(Color.PINK));
        ImageIcon icon2 = new ImageIcon("src/img/清空.png");
        btn2.setIcon(icon2);
        btn2.setOpaque(false);
        btn2.setBorder(new RoundBorder());
        btn2.setBorder(new RoundBorder(Color.PINK));

        btn1.setBounds(170, 100, 110, 40);
        btn2.setBounds(330, 100, 110, 40);

        employeeName.setBounds(40, 40, 200, 60);
        employeeNameField.setBounds(210, 50, 300, 40);

        part.setBounds(50, 150, 160, 60);
        partField.setBounds(210, 150, 300, 40);
        partField.setEditable(false);

        performance.setBounds(50, 200, 180, 60);
        performanceField.setBounds(210, 200, 300, 40);
        performanceField.setEditable(false);

        frame.add(btn1);
        frame.add(btn2);

        frame.add(employeeName);
        frame.add(employeeNameField);
        frame.add(part);
        frame.add(partField);
        frame.add(performance);
        frame.add(performanceField);

        btn1.addActionListener(this);
        btn2.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        Employee employee = new Employee();
        EmployeeSqlSeverImpl dao = new EmployeeSqlSeverImpl();
        String EmployeeName = employeeNameField.getText();
        if ("查询".equals(e.getActionCommand())) {
            if ("".equals(EmployeeName) ){
                JOptionPane.showMessageDialog(null, "请输入你的姓名进行查询！");
            } else {
                List<Employee> getname = dao.getByName(EmployeeName);
                for (Employee employee1 : getname) {
                    performanceField.setText(employee1.getPerformance());
                    partField.setText(employee1.getEmployee_part());
                    employeeNameField.setText(employee1.getEmployee_name());
                }

            }
        } else if ("清空".equals(e.getActionCommand())) {
            performanceField.setText("");
            partField.setText("");
            employeeNameField.setText("");
        }

    }
}
